package springboot.Controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import springboot.common.Result;
import springboot.entity.LjhsUser;
import springboot.service.ILjhsGoodsService;
import springboot.entity.LjhsGoods;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hys
 * @since 2022-06-01
 */
@RestController
@RequestMapping("/ljhsgoods")
public class LjhsGoodsController {
    @Resource
    private ILjhsGoodsService ljhsGoodsService;

    @PostMapping

    public Result save(@RequestBody LjhsGoods ljhsGoods){

        return Result.success(ljhsGoodsService.saveOrUpdate(ljhsGoods));
        }

        @DeleteMapping("/{id}")

        public Result delete(@PathVariable Integer id){

        return Result.success(ljhsGoodsService.removeById(id));
        }
        @PostMapping("/batch/del")
        public Result deleteBatch(@RequestBody List<Integer> ids){

        return Result.success(ljhsGoodsService.removeByIds(ids));
        }
        @GetMapping

        public Result index(){

        return Result.success(ljhsGoodsService.list());
        }

        @GetMapping("/{id}")

        public Result findOne(@PathVariable Integer id) {

        return Result.success(ljhsGoodsService.getById(id));
        }

        @GetMapping("/page")

        public Result findPage(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize,
                               @RequestParam(defaultValue = "") String name) {
            IPage<LjhsGoods> page = new Page<>(pageNum, pageSize);
            QueryWrapper<LjhsGoods> queryWrapper = new QueryWrapper<>();
            if (!"".equals(name)) {
                queryWrapper.like("name",name);
            }
            queryWrapper.orderByDesc("goodsId");
            return Result.success(ljhsGoodsService.page(page,queryWrapper));
        }


}

